﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// 文件名：ClsDepotSetDAL.cs
/// 作  者：Kidy
/// 时  间：2006.11.17
/// 说  明：ClsDepotSetDAL类用于仓库设置信息相关处理
/// </summary>
public class ClsDepotSetDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    /// <summary>
    /// 获取所有信息
    /// </summary>
    /// <returns>返回数据集</returns>
    public DataSet GetDepotSets()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetDataSet", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 用于查询窗口获取数据
    /// </summary>
    /// <returns></returns>
    public DataSet SearchDepotSets()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_QueryWinGetDataByDepot", con);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 模糊搜索仓库设置信息
    /// </summary>
    /// <param name="Key">搜索关键字</param>
    /// <returns>返回数据集</returns>
    public DataSet SearchDepotSets(string Key)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_SearchDepotSets", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@key", Key);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 作废仓库设置信息
    /// </summary>
    /// <param>仓库设置编号</param>
    /// <param name="Is_Visible">作废状态1为临时作废，－1为彻底作废</param>
    /// <returns>返回作废是否成功</returns>
    public Boolean DeleteDepotSet(string Wh_ID, int Is_Visible)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteDepotSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Wh_ID", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_ID"].Value = Wh_ID;
        com.Parameters.Add("@Is_Visible", SqlDbType.Int, 1);
        com.Parameters["@Is_Visible"].Value = Is_Visible;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 确认仓库设置信息
    /// </summary>
    /// <param>仓库设置编号</param>
    /// <param name="AuditStat">确认状态</param>
    /// <param name="Auditor">确认人</param>
    /// <returns>返回确认是否成功</returns>
    public Boolean AuditStatDepotSet(string Wh_ID, int AuditStat, string Auditor)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditStatSetDepotSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Wh_ID", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_ID"].Value = Wh_ID;
        com.Parameters.Add("@is_audit", SqlDbType.Int);
        com.Parameters["@is_audit"].Value = AuditStat;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 增加仓库设置信息
    /// </summary>
    /// <param>仓库设置编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean AddDepotSet(string strWh_ID, string strWh_Name, string strWh_Addr, string strWh_Postno, string strWh_Linkman, string strWh_Phone,
        string strWh_Dept, int iWh_Scon,int iWh_Ship,int iWh_Stock,int iWh_State,string Remark, string Oper)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddDepotSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Wh_ID", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_ID"].Value = strWh_ID;
        com.Parameters.Add("@Wh_Name", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_Name"].Value = strWh_Name;
        com.Parameters.Add("@Wh_Addr", SqlDbType.NVarChar, 60);
        com.Parameters["@Wh_Addr"].Value = strWh_Addr;
        com.Parameters.Add("@Wh_Postno", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_Postno"].Value = strWh_Postno;
        com.Parameters.Add("@Linkman", SqlDbType.NVarChar, 20);
        com.Parameters["@Linkman"].Value = strWh_Linkman;
        com.Parameters.Add("@Phone", SqlDbType.NVarChar, 20);
        com.Parameters["@Phone"].Value = strWh_Phone;
        com.Parameters.Add("@Wh_Dept", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_Dept"].Value = strWh_Dept;
        com.Parameters.Add("@Wh_Scon", SqlDbType.Int);
        com.Parameters["@Wh_Scon"].Value = iWh_Scon;
        com.Parameters.Add("@Wh_Ship", SqlDbType.Int);
        com.Parameters["@Wh_Ship"].Value = iWh_Ship;
        com.Parameters.Add("@Wh_Stock", SqlDbType.Int);
        com.Parameters["@Wh_Stock"].Value = iWh_Stock;
        com.Parameters.Add("@oper", SqlDbType.NVarChar, 60);
        com.Parameters["@oper"].Value = Oper;
        com.Parameters.Add("@Wh_State", SqlDbType.Int);
        com.Parameters["@Wh_State"].Value = iWh_State;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 修改仓库设置信息
    /// </summary>
    /// <param>仓库设置编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean UpDateDepotSet(string strWh_ID, string strWh_Name, string strWh_Addr, string strWh_Postno, string strWh_Linkman, string strWh_Phone,
        string strWh_Dept, int iWh_Scon, int iWh_Ship, int iWh_Stock, int iWh_State, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpDateDepotSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@Wh_ID", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_ID"].Value = strWh_ID;
        com.Parameters.Add("@Wh_Name", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_Name"].Value = strWh_Name;
        com.Parameters.Add("@Wh_Addr", SqlDbType.NVarChar, 60);
        com.Parameters["@Wh_Addr"].Value = strWh_Addr;
        com.Parameters.Add("@Wh_Postno", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_Postno"].Value = strWh_Postno;
        com.Parameters.Add("@Linkman", SqlDbType.NVarChar, 20);
        com.Parameters["@Linkman"].Value = strWh_Linkman;
        com.Parameters.Add("@Phone", SqlDbType.NVarChar, 20);
        com.Parameters["@Phone"].Value = strWh_Phone;
        com.Parameters.Add("@Wh_Dept", SqlDbType.NVarChar, 20);
        com.Parameters["@Wh_Dept"].Value = strWh_Dept;
        com.Parameters.Add("@Wh_Scon", SqlDbType.Int);
        com.Parameters["@Wh_Scon"].Value = iWh_Scon;
        com.Parameters.Add("@Wh_Ship", SqlDbType.Int);
        com.Parameters["@Wh_Ship"].Value = iWh_Ship;
        com.Parameters.Add("@Wh_Stock", SqlDbType.Int);
        com.Parameters["@Wh_Stock"].Value = iWh_Stock;
        com.Parameters.Add("@Wh_State", SqlDbType.Int);
        com.Parameters["@Wh_State"].Value = iWh_State;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

}
